//
//  DesignCenterSectionView.m
//  ForestPack
//
//  Created by jimmy on 2018/7/5.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "DesignCenterSectionView.h"
#import <Masonry.h>
#import "UIView+Utils.h"
#import "FPCustomButton.h"


#pragma mark - 第0区的区头
@implementation DesignCenterSectionView

+ (DesignCenterSectionView *)sectionViewWithHeight:(CGFloat)height
{
    DesignCenterSectionView * sectionView = [[DesignCenterSectionView alloc] initWithHeight:height];
    
    return sectionView;
}


- (instancetype)initWithHeight:(CGFloat)height
{
    self = [super init];
    if (self) {
        [self setViewUIWithHeight:height];
    }
    return self;
}

-(void)postListClicked
{
    if (_postListClick) {
        _postListClick();
    }
}

-(void)detailClicked
{
    if (_detailClick) {
        _detailClick();
    }
}

- (void)setViewUIWithHeight:(CGFloat)height
{
    UIImageView * leftImageV = [[UIImageView alloc] init];
    leftImageV.image = [UIImage imageNamed:@"公告"];
    [self addSubview:leftImageV];
    [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(16));
        make.centerY.equalTo(self);
        make.width.height.equalTo(@(19));
    }];
    
    FPLeftRightButton * rightBtn = [FPLeftRightButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setImage:[UIImage imageNamed:@"更多红色"] forState:UIControlStateNormal];
    [rightBtn setTitle:@"更多" forState:UIControlStateNormal];
    [rightBtn setTitleColor:RGB_COLOR(237,34,59) forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [rightBtn addTarget:self action:@selector(postListClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
        make.height.equalTo(@(30));
        make.width.equalTo(@(50));
    }];
    
    
    UIButton * foreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [foreButton setTitle:@"瓶贴设计包装设计茶包装设计食品包装标签设计" forState:UIControlStateNormal];
    [foreButton setTitleColor:RGB_COLOR(153,153,153) forState:UIControlStateNormal];
    foreButton.titleLabel.font = [UIFont systemFontOfSize:12];
    foreButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    foreButton.userInteractionEnabled = YES;
    [foreButton addTarget:self action:@selector(detailClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:foreButton];
    [foreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftImageV.mas_right).offset(5);
        make.right.equalTo(rightBtn.mas_left).offset(-5);
        make.centerY.equalTo(self);
    }];
    
}

@end


#pragma mark - 区头
@interface DesignCenterSectionHeaderView()

@property (nonatomic,strong)  UILabel * titleLab;

@end

@implementation DesignCenterSectionHeaderView

-(void)moreClick
{
    if (_reconmmandMoreClick) {
        _reconmmandMoreClick();
    }
    if (_designerShopMoreClick) {
        _designerShopMoreClick();
    }
    if (_yourDesignerMoreClick) {
        _yourDesignerMoreClick();
    }
    if (_creativeMoreClick) {
        _creativeMoreClick();
    }
}

+ (DesignCenterSectionHeaderView *)sectionHeaderViewWithHeight:(CGFloat)height withTitle:(NSString *)title
{
    DesignCenterSectionHeaderView * sectionView = [[DesignCenterSectionHeaderView alloc] initWithHeight:height withLabelText:title];
    
    return sectionView;
}


- (instancetype)initWithHeight:(CGFloat)height withLabelText:title
{
    self = [super init];
    if (self) {
        [self setViewUIWithHeight:height withLabelText:title];
    }
    return self;
}


- (void)setViewUIWithHeight:(CGFloat)height withLabelText:(NSString *)title
{
//    UIView * leftView = [[UIView alloc] init];
//    [self addSubview:leftView];
//    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.equalTo(@(0));
//        make.width.equalTo(@(3));
//        make.height.equalTo(self.mas_height).offset(-20);
//    }];
    
    UIImageView * leftImageV = [[UIImageView alloc] init];
    leftImageV.image = [UIImage imageNamed:@"红色矩形"];
    leftImageV.contentMode = UIViewContentModeScaleToFill;
    [self addSubview:leftImageV];
    [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@(3));
        make.height.equalTo(@23);
    }];
    
    FPLeftRightButton * rightBtn = [FPLeftRightButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setImage:[UIImage imageNamed:@"更多灰色"] forState:UIControlStateNormal];
    [rightBtn setTitle:@"更多" forState:UIControlStateNormal];
    [rightBtn setTitleColor:RGB_COLOR(153,153,153) forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [rightBtn addTarget:self action:@selector(moreClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
        make.height.equalTo(@(30));
        make.width.equalTo(@(50));
    }];
    
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.text = title;
    self.titleLab.textColor = FONTCOLOR_BLACK;
    self.titleLab.font = Ffont(18);
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftImageV.mas_right).offset(5);
        make.right.equalTo(rightBtn.mas_left).offset(-5);
        make.centerY.equalTo(self);
    }];
}


@end

#pragma mark - 区尾
@implementation DesignCenterSectionFooterView

-(void)publicReconmmand
{
    if (_reconmmandPublicClick) {
        _reconmmandPublicClick();
    }
}

+ (DesignCenterSectionFooterView *)sectionFooterViewWithHeight:(CGFloat)height
{
    DesignCenterSectionFooterView * sectionView = [[DesignCenterSectionFooterView alloc] initWithHeight:height];
    
    return sectionView;
}

- (instancetype)initWithHeight:(CGFloat)height
{
    self = [super init];
    if (self) {
        [self setViewUIWithHeight:height];
    }
    return self;
}

- (void)setViewUIWithHeight:(CGFloat)height
{
    
    UIButton * submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [submitBtn setTitle:@"发布需求" forState:UIControlStateNormal];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    submitBtn.titleLabel.font = Kfont(18);
    submitBtn.layer.masksToBounds = YES;
    submitBtn.layer.cornerRadius = 22;
    submitBtn.backgroundColor = RGBACOLOR(237,34,59,1);
    [submitBtn addTarget:self action:@selector(publicReconmmand) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(13);
        make.right.equalTo(self).offset(-13);
        make.bottom.equalTo(self).offset(-25);
        make.height.equalTo(@44);
    }];
    
    UIView * lineView = [[UIView alloc] init];
    lineView.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.left.right.equalTo(self);
        make.height.equalTo(@10);
    }];
    
    
}



@end


